package com.kehutong.applet.admin;

import com.kehutong.applet.entity.AppletMenuEntity;
import com.kehutong.applet.service.AppletMenuService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 菜单控制类
 * @author: joneron
 * @create: 2021/5/24
 **/
@MvcAction
@ReqMapping("/admin/crm/applet/menu")
public class AppletMenuController {

    @Inject
    AppletMenuService appletMenuService;

    @ReqMapping("/list")
    @HasPermission("crm:applet:menu:view")
    public Object list(JSONObject jsonObject) {
        return appletMenuService.findList(jsonObject);
    }

    @ReqMapping("/page")
    @HasPermission("crm:applet:menu:view")
    public Object page(JSONObject jsonObject) {
        return appletMenuService.findPage(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:applet:menu:edit")
    @ReqMapping("/save")
    public Object save(AppletMenuEntity appletMenuEntity, Token token) {
        appletMenuEntity.setCreateName(token.getUsername());
        return appletMenuService.save(appletMenuEntity);
    }

    @Bean(copy=true)
    @HasPermission("crm:applet:menu:edit")
    @ReqMapping("/update")
    public Object update(AppletMenuEntity appletMenuEntity) {

        return appletMenuService.update(appletMenuEntity);
    }

    @HasPermission("crm:applet:menu:edit")
    @ReqMapping("/delete")
    public Object delete(AppletMenuEntity appletMenuEntity) {

        return appletMenuService.deleteById(appletMenuEntity.getId());
    }

    @ReqMapping("/get")
    public Object get(AppletMenuEntity entity) {

        return Result.success(entity);
    }

}
